package wzh.crm.db;

import org.json.JSONException;
import org.json.JSONObject;
import org.jsoup.Connection;

import wzh.crm.vo.ProductVo;

/**
 * Created by wangzehao on 2016/6/15.
 */
public class ProductDB extends WebServiceDB<ProductVo> {

    public ProductVo toBean(JSONObject json) throws JSONException {
        ProductVo model=new ProductVo();
        model.setProductid(json.getInt("productid"));
        model.setProductname(json.getString("productname"));
        model.setProductsn(json.getString("productsn"));
        model.setStandardprice(json.optDouble("standardprice"));
        model.setSalesunit(json.getString("salesunit"));
        model.setUnitcost(json.optDouble("unitcost"));
        model.setClassification(json.getString("classification"));
        model.setPicture(json.getString("picture"));
        model.setIntroduction(json.getString("introduction"));
        model.setProductremarks(json.getString("productremarks"));
        return model;

    }

    public void toPost(ProductVo vo,Connection c){
        c.data("productid",Integer.toString(vo.getProductid()));
        c.data("productname",vo.getProductname());
        c.data("productsn",vo.getProductsn());
        c.data("standardprice",Double.toString(vo.getStandardprice()));
        c.data("salesunit",vo.getSalesunit());
        c.data("unitcost",vo.getSalesunit());
        c.data("classification",vo.getClassification());
        c.data("picture",vo.getPicture());
        c.data("introduction",vo.getIntroduction());
        c.data("productremarks",vo.getProductremarks());
    }

    @Override
    protected String listQueryMethod() {
        return "common_product_json";
    }

    @Override
    protected String idQueryMethod() {
        return null;
    }

    @Override
    protected String createMethod() {
        return "product_create_json";
    }

    @Override
    protected String modifyMethod() {
        return "product_modify_json";
    }
}
